import execjs, requests

headers = {
    # UA 要和JS代码里的UA保持一致
    "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36",
    "Referer": "https://www.douyin.com/user/MS4wLjABAAAAF0zlK2_5qCr5Lqy6zLNMH8W146aOetdfKSX95jYXwi8",
    "Cookie": "ttwid=1%7C6NVWeXpESfk2-orEB4oJvlD7cxOS1XItbYnTYb1LiQg%7C1709736433%7C597c6d80d00c638edd8503ac6114ba08dc7e2521df7687fc670691c2aed4f76e; douyin.com; device_web_cpu_core=20;"
}

with open("抖音.js") as f:
    js_data = f.read()

js_compile = execjs.compile(js_data)
url = "https://www.douyin.com/aweme/v1/web/general/search/single/?"
params = 'device_platform=webapp&aid=6383&channel=channel_pc_web&business_id=30068&count=8&penetrate_params=%7B%7D&pc_client_type=1&version_code=170400&version_name=17.4.0&cookie_enabled=true&screen_width=1707&screen_height=1067&browser_language=zh-CN&browser_platform=Win32&browser_name=Chrome&browser_version=122.0.0.0&browser_online=true&engine_name=Blink&engine_version=122.0.0.0&os_name=Windows&os_version=10&cpu_core_num=20&device_memory=8&platform=PC&downlink=10&effective_type=4g&round_trip_time=50&webid=7343261999907194422&msToken=jMtSA1O0TTxcwsLs2aLO9pjoTYTW41A2JT5uro2YbJhC5Oty1HcIgOjXtUC18oEo7D2XoATRFz7A39krvD8GnPSWEdc0GxZsenZB8Y91ZWUoc3Jlrn_Ci66V3jA='
xb_data = js_compile.call("get_x_bogus", params)
urls = url + params + "&X-Bogus=" + xb_data
print(urls)
response = requests.get(url=urls, headers=headers)
print(response)
print(response.text)
# print(response.json())